package disruptor;


import com.lmax.disruptor.EventHandler;


/**
 * @author: 李德才
 * @description:
 * @create: 2020-12-20 19:44
 **/

public class DisruptorEvent implements EventHandler<DisruptorEvent> {
    private String value;

    public void set(long value) {
        this.value = String.valueOf(value);
    }

    @Override
    public String toString() {
        return "LongEvent{" +
                "value=" + value +
                ",name=" + Thread.currentThread().getName() + " };";
    }


    /**
     * 这里使用自身清理自身的方法，在实际项目中可以构建集成关系，使用同一个类去做清理操作
     * 清理程序必须实现 EventHandler
     */

    public void clear() {
        this.value = null;
    }

    @Override
    public void onEvent(DisruptorEvent event, long sequence, boolean endOfBatch) throws Exception {
        event.clear();
    }
}
